<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <title>Ack Index</title>
    <script src="/javascripts/socket.io.js"></script>
</head>
<body>
    Ack
    <button onclick="sendMessage()">send</button>
    <script>

        var socket = io("http://192.168.1.65");

        socket.on('connect', function () {
            console.info("client connected netty-socketIo");
        });

        socket.on('disconnect', function () {
            console.info('client disconnected netty-socketIo')
        });

        socket.on('message', function (data, ackServerCallback) {
            console.info("data: " + data);

            if(ackServerCallback) {
                //send ack data to server
                ackServerCallback('server message was delivered to client!');
            }
        });

        socket.on('ackevent2', function (data, ackServerCallback, arg1) {
            console.info('response data : ' + data);
            if(ackServerCallback) {
                ackServerCallback('server message was delivered to client');
            }
        });

        socket.on('ackevent3', function (data, ackServerCallback) {
            console.info("response data: " + data);
            if (ackServerCallback) {
                ackServerCallback();
            }
        });

        function sendMessage() {
            var jsonObject = {userName:'lixuwei', message:'hi everyone!'};
            socket.emit('ackevent1', jsonObject, function (arg1, arg2) {

                console.info('ack from server! arg1: ' + arg1 + ", arg2: " + arg2);
            });
        }

    </script>
</body>
</html>